package com.panda.progress.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.panda.progress.dao.ProgressMapper;
import com.panda.progress.entity.MyCourses;
import com.panda.progress.entity.Progress;
import com.panda.progress.service.ProgressService;
 
@Service
public class ProgressServiceImp implements ProgressService {
	@Resource
	private ProgressMapper progressMapper;
	
	@Override
	public MyCourses findMyCourses(Long uid,Long gid) {
		return progressMapper.findMyCourses(uid,gid);
	}

	@Override
	public List<Progress> findByUId(Long uid,Long gid) {
		return progressMapper.findByUId(uid,gid);
	}

	@Override
	public void deleteById(Long id) {
		progressMapper.deleteByPrimaryKey(id);
	}

	@Override
	public Long saveOrUpdate(Progress progress) {
		if(progress.getId()==null){
			progressMapper.insert(progress);
		}else{
			Progress old = progressMapper.selectByPrimaryKey(progress.getId());
			old.setExplains(progress.getExplains());
			progressMapper.updateByPrimaryKey(old);
		}
		return progress.getId();
	}

	@Override
	public Long saveComment(Progress progress) {
		Progress old = progressMapper.selectByPrimaryKey(progress.getId());
		old.setComments(progress.getComments());
		progressMapper.updateByPrimaryKey(old);
		return progress.getId();
	}
	 
}
